package com.hyopt.modules.app.controller;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

/**
 * @ClassName ChartGPT
 * @Description TODO
 * @Author lijie
 * @Date 2023/2/8 11:02 星期三
 * @Version 1.0
 */
public class GptTokenUtil {

    public static final String ak = "552ff24d338766734cd6231f966e22c2";

    public static final String sk = "3103f70afb2f2ed3d1471d2ad81dd73e";

    public static void main(String[] args) {
        // 创建自己的token获取API（其中AK、SK在程序员盒子个人中心接口调用菜单下可以获取）
        String tokenApi = String.format("https://www.coderutil.com/api/openai/getToken?access-key=%s&secret-key=%s",
                ak, sk);
        // 请求获取token
        HttpRequest httpRequest = HttpUtil.createGet(tokenApi);
        HttpResponse response = httpRequest.execute();
        if (response.getStatus() == 200) {
            String body = response.body();
            System.out.println(body);
        }
    }

    public static String getToken(String ak, String sk) {
        // 创建自己的token获取API（其中AK、SK在程序员盒子个人中心接口调用菜单下可以获取）
        String tokenApi = String.format("https://www.coderutil.com/api/openai/getToken?access-key=%s&secret-key=%s",
                ak, sk);
        // 请求获取token
        HttpRequest httpRequest = HttpUtil.createGet(tokenApi);
        HttpResponse response = httpRequest.execute();
        String body = null;
        if (response.getStatus() == 200) {
            body = response.body();
            System.out.println(body);
        }
        return body;
    }
}
